package online.afeibaili.storebackendframework.model

import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import online.afeibaili.storebackendframework.model.json.JsonMapperAbstract


/**
 * 商品类
 *
 *@author AfeiBaili
 *@version 2025/10/17 16:03
 */

@Entity
@Table(name = "product")
class ProductEntity() {
    @Id
    var createTime: Long = 0
    var name: String = ""
    var price: Double = 0.0
    var isPoints: Boolean = false

    /** 多个图片使用,分割 */
    var images: String = ""
    var video: String = ""
    var description: String = ""

    /** 存入JSON格式
     * - materials ：存储材料（鲜花花材）
     * - flowerSay ：花语
     * - normalPrice ：正常价格
     * - tag ：适用人群（朋友/亲人/爱人...）
     */

    var detail: String = ""
    var category: String = ""
    var status: String = ""
    var remark: String = ""
    var sales: Long = 0

    constructor(
        name: String,
        price: Double,
        isPoints: Boolean,
        images: String,
        video: String,
        description: String,
        detail: String,
        category: String,
        status: String,
        remark: String,
    ) : this() {
        createTime = System.currentTimeMillis()
        this.name = name
        this.price = price
        this.isPoints = isPoints
        this.images = images
        this.video = video
        this.description = description
        this.detail = detail
        this.category = category
        this.status = status
        this.remark = remark
    }


    class DetailJsonMapper() {
        //存（玫瑰/百合/等等..）
        var materials = listOf<String>()
        var flowerSay = ""
        var normalPrice = 0

        //存（朋友/亲人/等等..）
        var tag = listOf<String>()

        constructor(materials: List<String>, flowerSay: String, normalPrice: Int, tag: List<String>) : this() {
            this.materials = materials
            this.flowerSay = flowerSay
            this.normalPrice = normalPrice
            this.tag = tag
        }

        companion object : JsonMapperAbstract<DetailJsonMapper>(DetailJsonMapper::class.java)
    }

    override fun toString(): String {
        return "ProductEntity(createTime=$createTime, name='$name', price=$price, isPoints=$isPoints, description='$description', detail='$detail', category='$category', status='$status', remark='$remark', sales=$sales)"
    }
}